import request from "@/utils/request";

import type { LoginFormDTO } from "@/types/login_register/LoginFormDTO";

import type { RegisterFormDTO } from "@/types/login_register/RegisterFormDTO";

/**
 * 登录
 * @param data
 * @returns
 */
export const loginApi = (data: LoginFormDTO) => {
  return request.post(
    "/api/user/login",
    {
      ...data,
    },
    {
      headers: {
        "Content-Type": "application/json",
      },
    }
  );
};

export const logoutApi = () => {
  return request.post("/api/user/logout", null, {
    headers: {
      "Content-Type": "application/json",
    },
  });
};


// 注册接口
export const registerApi = (data: RegisterFormDTO) => {
  return request.post(
    "/api/user/register",
    {
      ...data,
    },
    {
      headers: {
        "Content-Type": "application/json",
      },
    }
  );
};

// 获取验证码接口
export const getCaptchaApi = (phoneNumber: string) => {
  return request.post(
    `/api/captcha?phoneNumber=${encodeURIComponent(phoneNumber)}`,
    null, // 不传body
    {
      headers: {
        "Content-Type": "application/x-www-form-urlencoded", // 设置请求头为表单格式
      },
    }
  );
};
